home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / flow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-30  |  62.8 KB  |  2,051 lines

  1. /* Data flow analysis for GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains the data flow analysis pass of the compiler.
  22.    It computes data flow information
  23.    which tells combine_instructions which insns to consider combining
  24.    and controls register allocation.
  25.  
  26.    Additional data flow information that is too bulky to record
  27.    is generated during the analysis, and is used at that time to
  28.    create autoincrement and autodecrement addressing.
  29.  
  30.    The first step is dividing the function into basic blocks.
  31.    find_basic_blocks does this.  Then life_analysis determines
  32.    where each register is live and where it is dead.
  33.  
  34.    ** find_basic_blocks **
  35.  
  36.    find_basic_blocks divides the current function's rtl
  37.    into basic blocks.  It records the beginnings and ends of the
  38.    basic blocks in the vectors basic_block_head and basic_block_end,
  39.    and the number of blocks in n_basic_blocks.
  40.  
  41.    find_basic_blocks also finds any unreachable loops
  42.    and deletes them.
  43.  
  44.    ** life_analysis **
  45.  
  46.    life_analysis is called immediately after find_basic_blocks.
  47.    It uses the basic block information to determine where each
  48.    hard or pseudo register is live.
  49.  
  50.    ** live-register info **
  51.  
  52.    The information about where each register is live is in two parts:
  53.    the REG_NOTES of insns, and the vector basic_block_live_at_start.
  54.  
  55.    basic_block_live_at_start has an element for each basic block,
  56.    and the element is a bit-vector with a bit for each hard or pseudo
  57.    register.  The bit is 1 if the register is live at the beginning
  58.    of the basic block.
  59.  
  60.    To each insn's REG_NOTES is added an element for each register
  61.    that is live before the insn or set by the insn, but is dead
  62.    after the insn.
  63.  
  64.    To determine which registers are live after any insn, one can
  65.    start from the beginning of the basic block and scan insns, noting
  66.    which registers are set by each insn and which die there.
  67.  
  68.    ** Other actions of life_analysis **
  69.  
  70.    life_analysis sets up the LOG_LINKS fields of insns because the
  71.    information needed to do so is readily available.
  72.  
  73.    life_analysis deletes insns whose only effect is to store a value
  74.    that is never used.
  75.  
  76.    life_analysis notices cases where a reference to a register as
  77.    a memory address can be combined with a preceding or following
  78.    incrementation or decrementation of the register.  The separate
  79.    instruction to increment or decrement is deleted and the address
  80.    is changed to a POST_INC or similar rtx.
  81.  
  82.    Each time an incrementing or decrementing address is created,
  83.    a REG_INC element is added to the insn's REG_NOTES list.
  84.  
  85.    life_analysis fills in certain vectors containing information about
  86.    register usage: reg_n_refs, reg_n_deaths, reg_n_sets,
  87.    reg_live_length, reg_n_calls_crosses and reg_basic_block.  */
  88.  
  89. #include <stdio.h>
  90. #include "config.h"
  91. #include "rtl.h"
  92. #include "basic-block.h"
  93. #include "regs.h"
  94. #include "hard-reg-set.h"
  95. #include "flags.h"
  96.  
  97. #include "obstack.h"
  98. #define obstack_chunk_alloc xmalloc
  99. #define obstack_chunk_free free
  100.  
  101. extern int xmalloc ();
  102. extern void free ();
  103.  
  104. /* Get the basic block number of an insn.
  105.    This info should not be expected to remain available
  106.    after the end of life_analysis.  */
  107.  
  108. #define BLOCK_NUM(INSN)  uid_block_number[INSN_UID (INSN)]
  109.  
  110. /* This is where the BLOCK_NUM values are really stored.
  111.    This is set up by find_basic_blocks and used there and in life_analysis,
  112.    and then freed.  */
  113.  
  114. static short *uid_block_number;
  115.  
  116. /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile.  */
  117.  
  118. #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
  119. static char *uid_volatile;
  120.  
  121. /* Number of basic blocks in the current function.  */
  122.  
  123. int n_basic_blocks;
  124.  
  125. /* Maximum register number used in this function, plus one.  */
  126.  
  127. int max_regno;
  128.  
  129. /* Indexed by n, gives number of basic block that  (REG n) is used in.
  130.    If the value is REG_BLOCK_GLOBAL (-2),
  131.    it means (REG n) is used in more than one basic block.
  132.    REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
  133.    This information remains valid for the rest of the compilation
  134.    of the current function; it is used to control register allocation.  */
  135.  
  136. short *reg_basic_block;
  137.  
  138. /* Indexed by n, gives number of times (REG n) is used or set, each
  139.    weighted by its loop-depth.
  140.    This information remains valid for the rest of the compilation
  141.    of the current function; it is used to control register allocation.  */
  142.  
  143. short *reg_n_refs;
  144.  
  145. /* Indexed by n, gives number of times (REG n) is set.
  146.    This information remains valid for the rest of the compilation
  147.    of the current function; it is used to control register allocation.  */
  148.  
  149. short *reg_n_sets;
  150.  
  151. /* Indexed by N, gives number of places register N dies.
  152.    This information remains valid for the rest of the compilation
  153.    of the current function; it is used to control register allocation.  */
  154.  
  155. short *reg_n_deaths;
  156.  
  157. /* Indexed by N, gives 1 if that reg is live across any CALL_INSNs.
  158.    This information remains valid for the rest of the compilation
  159.    of the current function; it is used to control register allocation.  */
  160.  
  161. int *reg_n_calls_crossed;
  162.  
  163. /* Total number of instructions at which (REG n) is live.
  164.    The larger this is, the less priority (REG n) gets for
  165.    allocation in a real register.
  166.    This information remains valid for the rest of the compilation
  167.    of the current function; it is used to control register allocation.
  168.  
  169.    local-alloc.c may alter this number to change the priority.
  170.  
  171.    Negative values are special.
  172.    -1 is used to mark a pseudo reg which has a constant or memory equivalent
  173.    and is used infrequently enough that it should not get a hard register.
  174.    -2 is used to mark a pseudo reg for a parameter, when a frame pointer
  175.    is not required.  global-alloc.c makes an allocno for this but does
  176.    not try to assign a hard register to it.  */
  177.  
  178. int *reg_live_length;
  179.  
  180. /* Element N is the next insn that uses (hard or pseudo) register number N
  181.    within the current basic block; or zero, if there is no such insn.
  182.    This is valid only during the final backward scan in propagate_block.  */
  183.  
  184. static rtx *reg_next_use;
  185.  
  186. /* Size of a regset for the current function,
  187.    in (1) bytes and (2) elements.  */
  188.  
  189. int regset_bytes;
  190. int regset_size;
  191.  
  192. /* Element N is first insn in basic block N.
  193.    This info lasts until we finish compiling the function.  */
  194.  
  195. rtx *basic_block_head;
  196.  
  197. /* Element N is last insn in basic block N.
  198.    This info lasts until we finish compiling the function.  */
  199.  
  200. rtx *basic_block_end;
  201.  
  202. /* Element N is a regset describing the registers live
  203.    at the start of basic block N.
  204.    This info lasts until we finish compiling the function.  */
  205.  
  206. regset *basic_block_live_at_start;
  207.  
  208. /* Regset of regs live when calls to `setjmp'-like functions happen.  */
  209.  
  210. regset regs_live_at_setjmp;
  211.  
  212. /* Element N is nonzero if control can drop into basic block N
  213.    from the preceding basic block.  Freed after life_analysis.  */
  214.  
  215. static char *basic_block_drops_in;
  216.  
  217. /* Element N is depth within loops of basic block number N.
  218.    Freed after life_analysis.  */
  219.  
  220. static short *basic_block_loop_depth;
  221.  
  222. /* Element N nonzero if basic block N can actually be reached.
  223.    Vector exists only during find_basic_blocks.  */
  224.  
  225. static char *block_live_static;
  226.  
  227. /* Depth within loops of basic block being scanned for lifetime analysis,
  228.    plus one.  This is the weight attached to references to registers.  */
  229.  
  230. static int loop_depth;
  231.  
  232. /* Define AUTO_INC_DEC if machine has any kind of incrementing
  233.    or decrementing addressing.  */
  234.  
  235. #ifdef HAVE_PRE_DECREMENT
  236. #define AUTO_INC_DEC
  237. #endif
  238.  
  239. #ifdef HAVE_PRE_INCREMENT
  240. #define AUTO_INC_DEC
  241. #endif
  242.  
  243. #ifdef HAVE_POST_DECREMENT
  244. #define AUTO_INC_DEC
  245. #endif
  246.  
  247. #ifdef HAVE_POST_INCREMENT
  248. #define AUTO_INC_DEC
  249. #endif
  250.  
  251. /* Forward declarations */
  252. static void find_basic_blocks ();
  253. static void life_analysis ();
  254. static void mark_label_ref ();
  255. void allocate_for_life_analysis (); /* Used also in stupid_life_analysis */
  256. static void init_regset_vector ();
  257. static void propagate_block ();
  258. static void mark_set_regs ();
  259. static void mark_used_regs ();
  260. static int insn_dead_p ();
  261. static int libcall_dead_p ();
  262. static int try_pre_increment ();
  263. static int try_pre_increment_1 ();
  264. static rtx find_use_as_address ();
  265. void dump_flow_info ();
  266.  
  267. /* Find basic blocks of the current function and perform data flow analysis.
  268.    F is the first insn of the function and NREGS the number of register numbers
  269.    in use.  */
  270.  
  271. void
  272. flow_analysis (f, nregs, file)
  273.      rtx f;
  274.      int nregs;
  275.      FILE *file;
  276. {
  277.   register rtx insn;
  278.   register int i;
  279.   register int max_uid = 0;
  280.  
  281.   /* Count the basic blocks.  Also find maximum insn uid value used.  */
  282.  
  283.   {
  284.     register RTX_CODE prev_code = JUMP_INSN;
  285.     register RTX_CODE code;
  286.  
  287.     for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
  288.       {
  289.     code = GET_CODE (insn);
  290.     if (INSN_UID (insn) > max_uid)
  291.       max_uid = INSN_UID (insn);
  292.     if (code == CODE_LABEL
  293.         || (prev_code != INSN && prev_code != CALL_INSN
  294.         && prev_code != CODE_LABEL
  295.         && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
  296.       i++;
  297.     if (code != NOTE)
  298.       prev_code = code;
  299.       }
  300.   }
  301.  
  302.   /* Allocate some tables that last till end of compiling this function
  303.      and some needed only in find_basic_blocks and life_analysis.  */
  304.  
  305.   n_basic_blocks = i;
  306.   basic_block_head = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
  307.   basic_block_end = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
  308.   basic_block_drops_in = (char *) alloca (n_basic_blocks);
  309.   basic_block_loop_depth = (short *) alloca (n_basic_blocks * sizeof (short));
  310.   uid_block_number = (short *) alloca ((max_uid + 1) * sizeof (short));
  311.   uid_volatile = (char *) alloca (max_uid + 1);
  312.   bzero (uid_volatile, max_uid + 1);
  313.  
  314.   find_basic_blocks (f);
  315.   life_analysis (f, nregs);
  316.   if (file)
  317.     dump_flow_info (file);
  318.  
  319.   basic_block_drops_in = 0;
  320.   uid_block_number = 0;
  321.   basic_block_loop_depth = 0;
  322. }
  323.  
  324. /* Find all basic blocks of the function whose first insn is F.
  325.    Store the correct data in the tables that describe the basic blocks,
  326.    set up the chains of references for each CODE_LABEL, and
  327.    delete any entire basic blocks that cannot be reached.  */
  328.  
  329. static void
  330. find_basic_blocks (f)
  331.      rtx f;
  332. {
  333.   register rtx insn;
  334.   register int i;
  335.  
  336.   /* Initialize the ref chain of each label to 0.  */
  337.   /* Record where all the blocks start and end and their depth in loops.  */
  338.   /* For each insn, record the block it is in.  */
  339.  
  340.   {
  341.     register RTX_CODE prev_code = JUMP_INSN;
  342.     register RTX_CODE code;
  343.     int depth = 1;
  344.  
  345.     for (insn = f, i = -1; insn; insn = NEXT_INSN (insn))
  346.       {
  347.     code = GET_CODE (insn);
  348.     if (code == NOTE)
  349.       {
  350.         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
  351.           depth++;
  352.         else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  353.           depth--;
  354.       }
  355.     else if (code == CODE_LABEL
  356.          || (prev_code != INSN && prev_code != CALL_INSN
  357.              && prev_code != CODE_LABEL
  358.              && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
  359.       {
  360.         basic_block_head[++i] = insn;
  361.         basic_block_end[i] = insn;
  362.         basic_block_loop_depth[i] = depth;
  363.         if (code == CODE_LABEL)
  364.           LABEL_REFS (insn) = insn;
  365.       }
  366.     else if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
  367.       basic_block_end[i] = insn;
  368.     BLOCK_NUM (insn) = i;
  369.     if (code != NOTE)
  370.       prev_code = code;
  371.       }
  372.     if (i + 1 != n_basic_blocks)
  373.       abort ();
  374.   }
  375.  
  376.   /* Record which basic blocks control can drop in to.  */
  377.  
  378.   {
  379.     register int i;
  380.     for (i = 0; i < n_basic_blocks; i++)
  381.       {
  382.     register rtx insn = PREV_INSN (basic_block_head[i]);
  383.     /* TEMP1 is used to avoid a bug in Sequent's compiler.  */
  384.     register int temp1;
  385.     while (insn && GET_CODE (insn) == NOTE)
  386.       insn = PREV_INSN (insn);
  387.     temp1 = insn && GET_CODE (insn) != BARRIER;
  388.     basic_block_drops_in[i] = temp1;
  389.       }
  390.   }
  391.  
  392.   /* Now find which basic blocks can actually be reached
  393.      and put all jump insns' LABEL_REFS onto the ref-chains
  394.      of their target labels.  */
  395.  
  396.   if (n_basic_blocks > 0)
  397.     {
  398.       register char *block_live = (char *) alloca (n_basic_blocks);
  399.       register char *block_marked = (char *) alloca (n_basic_blocks);
  400.       int something_marked = 1;
  401.  
  402.       /* Initialize with just block 0 reachable and no blocks marked.  */
  403.  
  404.       bzero (block_live, n_basic_blocks);
  405.       bzero (block_marked, n_basic_blocks);
  406.       block_live[0] = 1;
  407.       block_live_static = block_live;
  408.  
  409.       /* Pass over all blocks, marking each block that is reachable
  410.      and has not yet been marked.
  411.      Keep doing this until, in one pass, no blocks have been marked.
  412.      Then blocks_live and blocks_marked are identical and correct.
  413.      In addition, all jumps actually reachable have been marked.  */
  414.  
  415.       while (something_marked)
  416.     {
  417.       something_marked = 0;
  418.       for (i = 0; i < n_basic_blocks; i++)
  419.         if (block_live[i] && !block_marked[i])
  420.           {
  421.         block_marked[i] = 1;
  422.         something_marked = 1;
  423.         if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1])
  424.           block_live[i + 1] = 1;
  425.         insn = basic_block_end[i];
  426.         if (GET_CODE (insn) == JUMP_INSN)
  427.           mark_label_ref (PATTERN (insn), insn, 0);
  428.           }
  429.     }
  430.  
  431.       /* Now delete the code for any basic blocks that can't be reached.
  432.      They can occur because jump_optimize does not recognize
  433.      unreachable loops as unreachable.  */
  434.  
  435.       for (i = 0; i < n_basic_blocks; i++)
  436.     if (!block_live[i])
  437.       {
  438.         insn = basic_block_head[i];
  439.         while (1)
  440.           {
  441.         if (GET_CODE (insn) == BARRIER)
  442.           abort ();
  443.         if (GET_CODE (insn) != NOTE)
  444.           {
  445.             PUT_CODE (insn, NOTE);
  446.             NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  447.             NOTE_SOURCE_FILE (insn) = 0;
  448.           }
  449.         if (insn == basic_block_end[i])
  450.           {
  451.             /* BARRIERs are between basic blocks, not part of one.
  452.                Delete a BARRIER if the preceding jump is deleted.
  453.                We cannot alter a BARRIER into a NOTE
  454.                because it is too short; but we can really delete
  455.                it because it is not part of a basic block.  */
  456.             if (NEXT_INSN (insn) != 0
  457.             && GET_CODE (NEXT_INSN (insn)) == BARRIER)
  458.               delete_insn (NEXT_INSN (insn));
  459.             break;
  460.           }
  461.         insn = NEXT_INSN (insn);
  462.           }
  463.         /* Each time we delete some basic blocks,
  464.            see if there is a jump around them that is
  465.            being turned into a no-op.  If so, delete it.  */
  466.  
  467.         if (block_live[i - 1])
  468.           {
  469.         register int j;
  470.         for (j = i; j < n_basic_blocks; j++)
  471.           if (block_live[j])
  472.             {
  473.               rtx label;
  474.               insn = basic_block_end[i - 1];
  475.               if (GET_CODE (insn) == JUMP_INSN
  476.               /* An unconditional jump is the only possibility
  477.                  we must check for, since a conditional one
  478.                  would make these blocks live.  */
  479.               && simplejump_p (insn)
  480.               && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1)
  481.               && INSN_UID (label) != 0
  482.               && BLOCK_NUM (label) == j)
  483.             {
  484.               PUT_CODE (insn, NOTE);
  485.               NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  486.               NOTE_SOURCE_FILE (insn) = 0;
  487.               if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
  488.                 abort ();
  489.               delete_insn (NEXT_INSN (insn));
  490.             }
  491.               break;
  492.             }
  493.           }
  494.       }
  495.     }
  496. }
  497.  
  498. /* Check expression X for label references;
  499.    if one is found, add INSN to the label's chain of references.
  500.  
  501.    CHECKDUP means check for and avoid creating duplicate references
  502.    from the same insn.  Such duplicates do no serious harm but
  503.    can slow life analysis.  CHECKDUP is set only when duplicates
  504.    are likely.  */
  505.  
  506. static void
  507. mark_label_ref (x, insn, checkdup)
  508.      rtx x, insn;
  509.      int checkdup;
  510. {
  511.   register RTX_CODE code = GET_CODE (x);
  512.   register int i;
  513.   register char *fmt;
  514.  
  515.   if (code == LABEL_REF)
  516.     {
  517.       register rtx label = XEXP (x, 0);
  518.       register rtx y;
  519.       if (GET_CODE (label) != CODE_LABEL)
  520.     abort ();
  521.       /* If the label was never emitted, this insn is junk,
  522.      but avoid a crash trying to refer to BLOCK_NUM (label).
  523.      This can happen as a result of a syntax error
  524.      and a diagnostic has already been printed.  */
  525.       if (INSN_UID (label) == 0)
  526.     return;
  527.       CONTAINING_INSN (x) = insn;
  528.       /* if CHECKDUP is set, check for duplicate ref from same insn
  529.      and don't insert.  */
  530.       if (checkdup)
  531.     for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y))
  532.       if (CONTAINING_INSN (y) == insn)
  533.         return;
  534.       LABEL_NEXTREF (x) = LABEL_REFS (label);
  535.       LABEL_REFS (label) = x;
  536.       block_live_static[BLOCK_NUM (label)] = 1;
  537.       return;
  538.     }
  539.  
  540.   fmt = GET_RTX_FORMAT (code);
  541.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  542.     {
  543.       if (fmt[i] == 'e')
  544.     mark_label_ref (XEXP (x, i), insn, 0);
  545.       if (fmt[i] == 'E')
  546.     {
  547.       register int j;
  548.       for (j = 0; j < XVECLEN (x, i); j++)
  549.         mark_label_ref (XVECEXP (x, i, j), insn, 1);
  550.     }
  551.     }
  552. }
  553.  
  554. /* Determine the which registers are live at the start of each
  555.    basic block of the function whose first insn is F.
  556.    NREGS is the number of registers used in F.
  557.    We allocate the vector basic_block_live_at_start
  558.    and the regsets that it points to, and fill them with the data.
  559.    regset_size and regset_bytes are also set here.  */
  560.  
  561. static void
  562. life_analysis (f, nregs)
  563.      rtx f;
  564.      int nregs;
  565. {
  566.   register regset tem;
  567.   int first_pass;
  568.   int changed;
  569.   /* For each basic block, a bitmask of regs
  570.      live on exit from the block.  */
  571.   regset *basic_block_live_at_end;
  572.   /* For each basic block, a bitmask of regs
  573.      live on entry to a successor-block of this block.
  574.      If this does not match basic_block_live_at_end,
  575.      that must be updated, and the block must be rescanned.  */
  576.   regset *basic_block_new_live_at_end;
  577.   /* For each basic block, a bitmask of regs
  578.      whose liveness at the end of the basic block
  579.      can make a difference in which regs are live on entry to the block.
  580.      These are the regs that are set within the basic block,
  581.      possibly excluding those that are used after they are set.  */
  582.   regset *basic_block_significant;
  583.   register int i;
  584.   rtx insn;
  585.  
  586.   struct obstack flow_obstack;
  587.  
  588.   obstack_init (&flow_obstack);
  589.  
  590.   max_regno = nregs;
  591.  
  592.   bzero (regs_ever_live, sizeof regs_ever_live);
  593.  
  594.   /* Allocate and zero out many data structures
  595.      that will record the data from lifetime analysis.  */
  596.  
  597.   allocate_for_life_analysis ();
  598.  
  599.   reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
  600.   bzero (reg_next_use, nregs * sizeof (rtx));
  601.  
  602.   /* Set up several regset-vectors used internally within this function.
  603.      Their meanings are documented above, with their declarations.  */
  604.  
  605.   basic_block_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
  606.   /* Don't use alloca since that leads to a crash rather than an error message
  607.      if there isn't enough space.
  608.      Don't use oballoc since we may need to allocate other things during
  609.      this function on the temporary obstack.  */
  610.   tem = (regset) obstack_alloc (&flow_obstack, n_basic_blocks * regset_bytes);
  611.   bzero (tem, n_basic_blocks * regset_bytes);
  612.   init_regset_vector (basic_block_live_at_end, tem, n_basic_blocks, regset_bytes);
  613.  
  614.   basic_block_new_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
  615.   tem = (regset) obstack_alloc (&flow_obstack, n_basic_blocks * regset_bytes);
  616.   bzero (tem, n_basic_blocks * regset_bytes);
  617.   init_regset_vector (basic_block_new_live_at_end, tem, n_basic_blocks, regset_bytes);
  618.  
  619.   basic_block_significant = (regset *) alloca (n_basic_blocks * sizeof (regset));
  620.   tem = (regset) obstack_alloc (&flow_obstack, n_basic_blocks * regset_bytes);
  621.   bzero (tem, n_basic_blocks * regset_bytes);
  622.   init_regset_vector (basic_block_significant, tem, n_basic_blocks, regset_bytes);
  623.  
  624.   /* Record which insns refer to any volatile memory
  625.      or for any reason can't be deleted just because they are dead stores.
  626.      Also, delete any insns that copy a register to itself. */
  627.  
  628.   for (insn = f; insn; insn = NEXT_INSN (insn))
  629.     {
  630.       enum rtx_code code1 = GET_CODE (insn);
  631.       if (code1 == CALL_INSN)
  632.     INSN_VOLATILE (insn) = 1;
  633.       else if (code1 == INSN || code1 == JUMP_INSN)
  634.     {
  635.       if (GET_CODE (PATTERN (insn)) == SET
  636.           && GET_CODE (SET_DEST (PATTERN (insn))) == REG
  637.           && GET_CODE (SET_SRC (PATTERN (insn))) == REG
  638.           && REGNO (SET_DEST (PATTERN (insn))) ==
  639.             REGNO (SET_SRC (PATTERN (insn))))
  640.         {
  641.           PUT_CODE (insn, NOTE);
  642.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  643.           NOTE_SOURCE_FILE (insn) = 0;
  644.         }
  645.       else if (GET_CODE (PATTERN (insn)) != USE)
  646.         INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn));
  647.     }
  648.       /* A SET that makes space on the stack cannot be dead.
  649.      (Such SETs occur only for allocating variable-size data,
  650.      so they will always have a PLUS or MINUS according to the
  651.      direction of stack growth.)
  652.      Even if this function never uses this stack pointer value,
  653.      signal handlers do!  */
  654.       else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
  655.            && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
  656. #ifdef STACK_GROWS_DOWNWARD
  657.            && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
  658. #else
  659.            && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
  660. #endif
  661.            && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
  662.     INSN_VOLATILE (insn) = 1;
  663.     }
  664.  
  665.   if (n_basic_blocks > 0)
  666. #ifdef EXIT_IGNORE_STACK
  667.     if (! (EXIT_IGNORE_STACK) || ! frame_pointer_needed)
  668. #endif
  669.       {
  670.     /* If exiting needs the right stack value,
  671.        consider the stack pointer live at the end of the function.  */
  672.     basic_block_live_at_end[n_basic_blocks - 1]
  673.       [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  674.         |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
  675.     basic_block_new_live_at_end[n_basic_blocks - 1]
  676.       [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  677.         |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
  678.       }
  679.  
  680.   /* Propagate life info through the basic blocks
  681.      around the graph of basic blocks.
  682.  
  683.      This is a relaxation process: each time a new register
  684.      is live at the end of the basic block, we must scan the block
  685.      to determine which registers are, as a consequence, live at the beginning
  686.      of that block.  These registers must then be marked live at the ends
  687.      of all the blocks that can transfer control to that block.
  688.      The process continues until it reaches a fixed point.  */
  689.  
  690.   first_pass = 1;
  691.   changed = 1;
  692.   while (changed)
  693.     {
  694.       changed = 0;
  695.       for (i = n_basic_blocks - 1; i >= 0; i--)
  696.     {
  697.       int consider = first_pass;
  698.       int must_rescan = first_pass;
  699.       register int j;
  700.  
  701.       /* Set CONSIDER if this block needs thinking about at all
  702.          (that is, if the regs live now at the end of it
  703.          are not the same as were live at the end of it when
  704.          we last thought about it).
  705.          Set must_rescan if it needs to be thought about
  706.          instruction by instruction (that is, if any additional
  707.          reg that is live at the end now but was not live there before
  708.          is one of the significant regs of this basic block).  */
  709.  
  710.       for (j = 0; j < regset_size; j++)
  711.         {
  712.           register int x = basic_block_new_live_at_end[i][j]
  713.               & ~basic_block_live_at_end[i][j];
  714.           if (x)
  715.         consider = 1;
  716.           if (x & basic_block_significant[i][j])
  717.         {
  718.           must_rescan = 1;
  719.           consider = 1;
  720.           break;
  721.         }
  722.         }
  723.  
  724.       if (! consider)
  725.         continue;
  726.  
  727.       /* The live_at_start of this block may be changing,
  728.          so another pass will be required after this one.  */
  729.       changed = 1;
  730.  
  731.       if (! must_rescan)
  732.         {
  733.           /* No complete rescan needed;
  734.          just record those variables newly known live at end
  735.          as live at start as well.  */
  736.           for (j = 0; j < regset_size; j++)
  737.         {
  738.           register int x = basic_block_new_live_at_end[i][j]
  739.             & ~basic_block_live_at_end[i][j];
  740.           basic_block_live_at_start[i][j] |= x;
  741.           basic_block_live_at_end[i][j] |= x;
  742.         }
  743.         }
  744.       else
  745.         {
  746.           /* Update the basic_block_live_at_start
  747.          by propagation backwards through the block.  */
  748.           bcopy (basic_block_new_live_at_end[i],
  749.              basic_block_live_at_end[i], regset_bytes);
  750.           bcopy (basic_block_live_at_end[i],
  751.              basic_block_live_at_start[i], regset_bytes);
  752.           propagate_block (basic_block_live_at_start[i],
  753.                    basic_block_head[i], basic_block_end[i], 0,
  754.                    first_pass ? basic_block_significant[i] : 0,
  755.                    i);
  756.         }
  757.  
  758.       {
  759.         register rtx jump, head;
  760.         /* Update the basic_block_new_live_at_end's of the block
  761.            that falls through into this one (if any).  */
  762.         head = basic_block_head[i];
  763.         jump = PREV_INSN (head);
  764.         if (basic_block_drops_in[i])
  765.           {
  766.         register int from_block = BLOCK_NUM (jump);
  767.         register int j;
  768.         for (j = 0; j < regset_size; j++)
  769.           basic_block_new_live_at_end[from_block][j]
  770.             |= basic_block_live_at_start[i][j];
  771.           }
  772.         /* Update the basic_block_new_live_at_end's of
  773.            all the blocks that jump to this one.  */
  774.         if (GET_CODE (head) == CODE_LABEL)
  775.           for (jump = LABEL_REFS (head);
  776.            jump != head;
  777.            jump = LABEL_NEXTREF (jump))
  778.         {
  779.           register int from_block = BLOCK_NUM (CONTAINING_INSN (jump));
  780.           register int j;
  781.           for (j = 0; j < regset_size; j++)
  782.             basic_block_new_live_at_end[from_block][j]
  783.               |= basic_block_live_at_start[i][j];
  784.         }
  785.       }
  786. #ifdef USE_C_ALLOCA
  787.       alloca (0);
  788. #endif
  789.     }
  790.       first_pass = 0;
  791.     }
  792.  
  793. #if 0 /* This seems unnecessary; life at start of function shouldn't
  794.      mean that the reg is live in more than one basic block.  */
  795.  
  796.   /* Process the regs live at the beginning of the function.
  797.      Mark them as not local to any one basic block.  */
  798.  
  799.   if (n_basic_blocks > 0)
  800.     for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  801.       if (basic_block_live_at_start[0][i / REGSET_ELT_BITS]
  802.       & (1 << (i % REGSET_ELT_BITS)))
  803.     reg_basic_block[i] = REG_BLOCK_GLOBAL;
  804. #endif
  805.  
  806.   /* Now the life information is accurate.
  807.      Make one more pass over each basic block
  808.      to delete dead stores, create autoincrement addressing
  809.      and record how many times each register is used, is set, or dies.
  810.  
  811.      To save time, we operate directly in basic_block_live_at_end[i],
  812.      thus destroying it (in fact, converting it into a copy of
  813.      basic_block_live_at_start[i]).  This is ok now because
  814.      basic_block_live_at_end[i] is no longer used past this point.  */
  815.  
  816.   for (i = 0; i < n_basic_blocks; i++)
  817.     {
  818.       propagate_block (basic_block_live_at_end[i],
  819.                basic_block_head[i], basic_block_end[i], 1, 0, i);
  820. #ifdef USE_C_ALLOCA
  821.       alloca (0);
  822. #endif
  823.     }
  824.  
  825.   /* Something live during a setjmp should not be put in a register
  826.      on certain machines which restore regs from stack frames
  827.      rather than from the jmpbuf.
  828.      But we don't need to do this for the user's variables, since
  829.      ANSI says only volatile variables need this.  */
  830. #ifdef LONGJMP_RESTORE_FROM_STACK
  831.   for (i = FIRST_PSEUDO_REGISTER; i < nregs; i++)
  832.     if (regs_live_at_setjmp[i / REGSET_ELT_BITS] & (1 << (i % REGSET_ELT_BITS))
  833.     && regno_reg_rtx[i] != 0 && ! REG_USERVAR_P (regno_reg_rtx[i]))
  834.       {
  835.     reg_live_length[i] = -1;
  836.     reg_basic_block[i] = -1;
  837.       }
  838. #endif
  839.  
  840.   obstack_free (&flow_obstack, 0);
  841. }
  842.  
  843. /* Subroutines of life analysis.  */
  844.  
  845. /* Allocate the permanent data structures that represent the results
  846.    of life analysis.  Not static since used also for stupid life analysis.  */
  847.  
  848. void
  849. allocate_for_life_analysis ()
  850. {
  851.   register int i;
  852.   register regset tem;
  853.  
  854.   regset_size = ((max_regno + REGSET_ELT_BITS - 1) / REGSET_ELT_BITS);
  855.   regset_bytes = regset_size * sizeof (*(regset)0);
  856.  
  857.   reg_n_refs = (short *) oballoc (max_regno * sizeof (short));
  858.   bzero (reg_n_refs, max_regno * sizeof (short));
  859.  
  860.   reg_n_sets = (short *) oballoc (max_regno * sizeof (short));
  861.   bzero (reg_n_sets, max_regno * sizeof (short));
  862.  
  863.   reg_n_deaths = (short *) oballoc (max_regno * sizeof (short));
  864.   bzero (reg_n_deaths, max_regno * sizeof (short));
  865.  
  866.   reg_live_length = (int *) oballoc (max_regno * sizeof (int));
  867.   bzero (reg_live_length, max_regno * sizeof (int));
  868.  
  869.   reg_n_calls_crossed = (int *) oballoc (max_regno * sizeof (int));
  870.   bzero (reg_n_calls_crossed, max_regno * sizeof (int));
  871.  
  872.   reg_basic_block = (short *) oballoc (max_regno * sizeof (short));
  873.   for (i = 0; i < max_regno; i++)
  874.     reg_basic_block[i] = REG_BLOCK_UNKNOWN;
  875.  
  876.   basic_block_live_at_start = (regset *) oballoc (n_basic_blocks * sizeof (regset));
  877.   tem = (regset) oballoc (n_basic_blocks * regset_bytes);
  878.   bzero (tem, n_basic_blocks * regset_bytes);
  879.   init_regset_vector (basic_block_live_at_start, tem, n_basic_blocks, regset_bytes);
  880.  
  881.   regs_live_at_setjmp = (regset) oballoc (regset_bytes);
  882.   bzero (regs_live_at_setjmp, regset_bytes);
  883. }
  884.  
  885. /* Make each element of VECTOR point at a regset,
  886.    taking the space for all those regsets from SPACE.
  887.    SPACE is of type regset, but it is really as long as NELTS regsets.
  888.    BYTES_PER_ELT is the number of bytes in one regset.  */
  889.  
  890. static void
  891. init_regset_vector (vector, space, nelts, bytes_per_elt)
  892.      regset *vector;
  893.      regset space;
  894.      int nelts;
  895.      int bytes_per_elt;
  896. {
  897.   register int i;
  898.   register regset p = space;
  899.  
  900.   for (i = 0; i < nelts; i++)
  901.     {
  902.       vector[i] = p;
  903.       p += bytes_per_elt / sizeof (*p);
  904.     }
  905. }
  906.  
  907. /* Compute the registers live at the beginning of a basic block
  908.    from those live at the end.
  909.  
  910.    When called, OLD contains those live at the end.
  911.    On return, it contains those live at the beginning.
  912.    FIRST and LAST are the first and last insns of the basic block.
  913.  
  914.    FINAL is nonzero if we are doing the final pass which is not
  915.    for computing the life info (since that has already been done)
  916.    but for acting on it.  On this pass, we delete dead stores,
  917.    set up the logical links and dead-variables lists of instructions,
  918.    and merge instructions for autoincrement and autodecrement addresses.
  919.  
  920.    SIGNIFICANT is nonzero only the first time for each basic block.
  921.    If it is nonzero, it points to a regset in which we store
  922.    a 1 for each register that is set within the block.
  923.  
  924.    BNUM is the number of the basic block.  */
  925.  
  926. static void
  927. propagate_block (old, first, last, final, significant, bnum)
  928.      register regset old;
  929.      rtx first;
  930.      rtx last;
  931.      int final;
  932.      regset significant;
  933.      int bnum;
  934. {
  935.   register rtx insn;
  936.   rtx prev;
  937.   regset live;
  938.   regset dead;
  939.  
  940.   /* The following variables are used only if FINAL is nonzero.  */
  941.   /* This vector gets one element for each reg that has been live
  942.      at any point in the basic block that has been scanned so far.
  943.      SOMETIMES_MAX says how many elements are in use so far.
  944.      In each element, OFFSET is the byte-number within a regset
  945.      for the register described by the element, and BIT is a mask
  946.      for that register's bit within the byte.  */
  947.   register struct foo { short offset; short bit; } *regs_sometimes_live;
  948.   int sometimes_max = 0;
  949.   /* This regset has 1 for each reg that we have seen live so far.
  950.      It and REGS_SOMETIMES_LIVE are updated together.  */
  951.   regset maxlive;
  952.  
  953.   loop_depth = basic_block_loop_depth[bnum];
  954.  
  955.   dead = (regset) alloca (regset_bytes);
  956.   live = (regset) alloca (regset_bytes);
  957.  
  958.   if (final)
  959.     {
  960.       register int i, offset, bit;
  961.  
  962.       maxlive = (regset) alloca (regset_bytes);
  963.       bcopy (old, maxlive, regset_bytes);
  964.       regs_sometimes_live
  965.     = (struct foo *) alloca (max_regno * sizeof (struct foo));
  966.  
  967.       /* Process the regs live at the end of the block.
  968.      Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
  969.      Also mark them as not local to any one basic block.  */
  970.  
  971.       for (offset = 0, i = 0; offset < regset_size; offset++)
  972.     for (bit = 1; bit; bit <<= 1, i++)
  973.       {
  974.         if (i == max_regno)
  975.           break;
  976.         if (old[offset] & bit)
  977.           {
  978.         reg_basic_block[i] = REG_BLOCK_GLOBAL;
  979.         regs_sometimes_live[sometimes_max].offset = offset;
  980.         regs_sometimes_live[sometimes_max].bit = i % REGSET_ELT_BITS;
  981.         sometimes_max++;
  982.           }
  983.       }
  984.     }
  985.  
  986.   /* Scan the block an insn at a time from end to beginning.  */
  987.  
  988.   for (insn = last; ; insn = prev)
  989.     {
  990.       prev = PREV_INSN (insn);
  991.  
  992.       /* If this is a call to `setjmp' et al,
  993.      warn if any non-volatile datum is live.  */
  994.  
  995.       if (final && GET_CODE (insn) == NOTE
  996.       && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
  997.     {
  998.       int i;
  999.       for (i = 0; i < regset_size; i++)
  1000.         regs_live_at_setjmp[i] |= old[i];
  1001.     }
  1002.  
  1003.       /* Update the life-status of regs for this insn.
  1004.      First DEAD gets which regs are set in this insn
  1005.      then LIVE gets which regs are used in this insn.
  1006.      Then the regs live before the insn
  1007.      are those live after, with DEAD regs turned off,
  1008.      and then LIVE regs turned on.  */
  1009.  
  1010.       if (GET_CODE (insn) == INSN
  1011.       || GET_CODE (insn) == JUMP_INSN
  1012.       || GET_CODE (insn) == CALL_INSN)
  1013.     {
  1014.       register int i;
  1015.       rtx note = find_reg_note (insn, REG_RETVAL, 0);
  1016.  
  1017.       /* If an instruction consists of just dead store(s) on final pass,
  1018.          "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
  1019.          We could really delete it with delete_insn, but that
  1020.          can cause trouble for first or last insn in a basic block.  */
  1021.       if (final && insn_dead_p (PATTERN (insn), old, 1)
  1022.           /* Don't delete something that refers to volatile storage!  */
  1023.           && ! INSN_VOLATILE (insn))
  1024.         {
  1025.           rtx oldpat = PATTERN (insn);
  1026.           PUT_CODE (insn, NOTE);
  1027.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1028.           NOTE_SOURCE_FILE (insn) = 0;
  1029.           /* If this insn is copying the return value from a library call,
  1030.          delete the entire library call.  */
  1031.           if (note && libcall_dead_p (oldpat, old))
  1032.         {
  1033.           rtx first = XEXP (note, 0);
  1034.           rtx prev = insn;
  1035.           while (INSN_DELETED_P (first))
  1036.             first = NEXT_INSN (first);
  1037.           while (prev != first)
  1038.             {
  1039.               prev = PREV_INSN (prev);
  1040.               PUT_CODE (prev, NOTE);
  1041.               NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
  1042.               NOTE_SOURCE_FILE (prev) = 0;
  1043.             }
  1044.         }
  1045.           goto flushed;
  1046.         }
  1047.  
  1048.       for (i = 0; i < regset_size; i++)
  1049.         {
  1050.           dead[i] = 0;    /* Faster than bzero here */
  1051.           live[i] = 0;    /* since regset_size is usually small */
  1052.         }
  1053.  
  1054.       /* See if this is an increment or decrement that can be
  1055.          merged into a following memory address.  */
  1056. #ifdef AUTO_INC_DEC
  1057.       {
  1058.         register rtx x = PATTERN (insn);
  1059.         /* Does this instruction increment or decrement a register?  */
  1060.         if (final && GET_CODE (x) == SET
  1061.         && GET_CODE (SET_DEST (x)) == REG
  1062.         && (GET_CODE (SET_SRC (x)) == PLUS
  1063.             || GET_CODE (SET_SRC (x)) == MINUS)
  1064.         && XEXP (SET_SRC (x), 0) == SET_DEST (x)
  1065.         && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
  1066.         /* Ok, look for a following memory ref we can combine with.
  1067.            If one is found, change the memory ref to a PRE_INC
  1068.            or PRE_DEC, cancel this insn, and return 1.
  1069.            Return 0 if nothing has been done.  */
  1070.         && try_pre_increment_1 (insn))
  1071.           goto flushed;
  1072.       }
  1073. #endif /* AUTO_INC_DEC */
  1074.  
  1075.       /* If this is not the final pass, and this insn is copying the
  1076.          value of a library call and it's dead, don't scan the
  1077.          insns that perform the library call, so that the call's
  1078.          arguments are not marked live.  */
  1079.       if (note && insn_dead_p (PATTERN (insn), old, 1)
  1080.           && libcall_dead_p (PATTERN (insn), old))
  1081.         {
  1082.           /* Mark the dest reg as `significant'.  */
  1083.           mark_set_regs (old, dead, PATTERN (insn), 0, significant);
  1084.  
  1085.           insn = XEXP (note, 0);
  1086.           prev = PREV_INSN (insn);
  1087.         }
  1088.       else if (GET_CODE (PATTERN (insn)) == SET
  1089.            && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
  1090.            && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
  1091.            && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
  1092.            && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
  1093.         /* We have an insn to pop a constant amount off the stack.
  1094.            (Such insns use PLUS regardless of the direction of the stack,
  1095.            and any insn to adjust the stack by a constant is always a pop.)
  1096.            These insns, if not dead stores, have no effect on life.  */
  1097.         ;
  1098.       else
  1099.         {
  1100.           /* LIVE gets the regs used in INSN; DEAD gets those set by it.  */
  1101.           mark_set_regs (old, dead, PATTERN (insn), final ? insn : 0,
  1102.                  significant);
  1103.           mark_used_regs (old, live, PATTERN (insn), final, insn);
  1104.  
  1105.           /* Update OLD for the registers used or set.  */
  1106.           for (i = 0; i < regset_size; i++)
  1107.         {
  1108.           old[i] &= ~dead[i];
  1109.           old[i] |= live[i];
  1110.         }
  1111.  
  1112.           if (GET_CODE (insn) == CALL_INSN)
  1113.         {
  1114.           register int i;
  1115.  
  1116.           /* Each call clobbers all call-clobbered regs.
  1117.              Note that the function-value reg is one of these, and
  1118.              mark_set_regs has already had a chance to handle it.  */
  1119.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1120.             if (call_used_regs[i])
  1121.               dead[i / REGSET_ELT_BITS] |=
  1122.             (1 << (i % REGSET_ELT_BITS));
  1123.  
  1124.           /* The stack ptr is used (honorarily) by a CALL insn.  */
  1125.           live[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  1126.             |= (1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS));
  1127.         }
  1128.  
  1129.           /* Update OLD for the registers used or set.  */
  1130.           for (i = 0; i < regset_size; i++)
  1131.         {
  1132.           old[i] &= ~dead[i];
  1133.           old[i] |= live[i];
  1134.         }
  1135.  
  1136.           if (GET_CODE (insn) == CALL_INSN && final)
  1137.         {
  1138.           /* Any regs live at the time of a call instruction
  1139.              must not go in a register clobbered by calls.
  1140.              Find all regs now live and record this for them.  */
  1141.  
  1142.           register struct foo *p = regs_sometimes_live;
  1143.  
  1144.           for (i = 0; i < sometimes_max; i++, p++)
  1145.             if (old[p->offset] & (1 << p->bit))
  1146.               reg_n_calls_crossed[p->offset * REGSET_ELT_BITS + p->bit]+= 1;
  1147.         }
  1148.         }
  1149.  
  1150.       /* On final pass, add any additional sometimes-live regs
  1151.          into MAXLIVE and REGS_SOMETIMES_LIVE.
  1152.          Also update counts of how many insns each reg is live at.  */
  1153.  
  1154.       if (final)
  1155.         {
  1156.           for (i = 0; i < regset_size; i++)
  1157.         {
  1158.           register int diff = live[i] & ~maxlive[i];
  1159.  
  1160.           if (diff)
  1161.             {
  1162.               register int regno;
  1163.               maxlive[i] |= diff;
  1164.               for (regno = 0; diff && regno < REGSET_ELT_BITS; regno++)
  1165.             if (diff & (1 << regno))
  1166.               {
  1167.                 regs_sometimes_live[sometimes_max].offset = i;
  1168.                 regs_sometimes_live[sometimes_max].bit = regno;
  1169.                 diff &= ~ (1 << regno);
  1170.                 sometimes_max++;
  1171.               }
  1172.             }
  1173.         }
  1174.  
  1175.           {
  1176.         register struct foo *p = regs_sometimes_live;
  1177.         for (i = 0; i < sometimes_max; i++, p++)
  1178.           {
  1179.             if (old[p->offset] & (1 << p->bit))
  1180.               reg_live_length[p->offset * REGSET_ELT_BITS + p->bit]++;
  1181.           }
  1182.           }
  1183.         }
  1184.     }
  1185.     flushed: ;
  1186.       if (insn == first)
  1187.     break;
  1188.     }
  1189. }
  1190.  
  1191. /* Return 1 if X (the body of an insn, or part of it) is just dead stores
  1192.    (SET expressions whose destinations are registers dead after the insn).
  1193.    NEEDED is the regset that says which regs are alive after the insn.  */
  1194.  
  1195. static int
  1196. insn_dead_p (x, needed, strict_low_ok)
  1197.      rtx x;
  1198.      regset needed;
  1199.      int strict_low_ok;
  1200. {
  1201.   register RTX_CODE code = GET_CODE (x);
  1202. #if 0
  1203.   /* Make sure insns to set the stack pointer are never deleted.  */
  1204.   needed[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
  1205.     |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
  1206. #endif
  1207.  
  1208.   /* If setting something that's a reg or part of one,
  1209.      see if that register's altered value will be live.  */
  1210.  
  1211.   if (code == SET)
  1212.     {
  1213.       register rtx r = SET_DEST (x);
  1214.       /* A SET that is a subroutine call cannot be dead.  */
  1215.       if (GET_CODE (SET_SRC (x)) == CALL)
  1216.     return 0;
  1217.       while (GET_CODE (r) == SUBREG
  1218.          || (strict_low_ok && GET_CODE (r) == STRICT_LOW_PART)
  1219.          || GET_CODE (r) == ZERO_EXTRACT
  1220.          || GET_CODE (r) == SIGN_EXTRACT)
  1221.     r = SUBREG_REG (r);
  1222.       if (GET_CODE (r) == REG)
  1223.     {
  1224.       register int regno = REGNO (r);
  1225.       register int offset = regno / REGSET_ELT_BITS;
  1226.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1227.       return (! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
  1228.           && (needed[offset] & bit) == 0);
  1229.     }
  1230.     }
  1231.   /* If performing several activities,
  1232.      insn is dead if each activity is individually dead.
  1233.      Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
  1234.      that's inside a PARALLEL doesn't make the insn worth keeping.  */
  1235.   else if (code == PARALLEL)
  1236.     {
  1237.       register int i = XVECLEN (x, 0);
  1238.       for (i--; i >= 0; i--)
  1239.     {
  1240.       rtx elt = XVECEXP (x, 0, i);
  1241.       if (!insn_dead_p (elt, needed, strict_low_ok)
  1242.           && GET_CODE (elt) != CLOBBER
  1243.           && GET_CODE (elt) != USE)
  1244.         return 0;
  1245.     }
  1246.       return 1;
  1247.     }
  1248.   /* We do not check CLOBBER or USE here.
  1249.      An insn consisting of just a CLOBBER or just a USE
  1250.      should not be deleted.  */
  1251.   return 0;
  1252. }
  1253.  
  1254. /* If X is the last insn in a libcall, and assuming X is dead,
  1255.    return 1 if the entire library call is dead.
  1256.    This is true if the source of X is a dead register
  1257.    (as well as the destination, which we tested already).
  1258.    If this insn doesn't just copy a register, then we don't
  1259.    have an ordinary libcall.  In that case, cse could not have
  1260.    managed to substitute the source for the dest later on,
  1261.    so we can assume the libcall is dead.  */
  1262.  
  1263. static int
  1264. libcall_dead_p (x, needed)
  1265.      rtx x;
  1266.      regset needed;
  1267. {
  1268.   register RTX_CODE code = GET_CODE (x);
  1269.  
  1270.   if (code == SET)
  1271.     {
  1272.       register rtx r = SET_SRC (x);
  1273.       if (GET_CODE (r) == REG)
  1274.     {
  1275.       register int regno = REGNO (r);
  1276.       register int offset = regno / REGSET_ELT_BITS;
  1277.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1278.       return (needed[offset] & bit) == 0;
  1279.     }
  1280.     }
  1281.   return 1;
  1282. }
  1283.  
  1284. /* Return 1 if register REGNO was used before it was set.
  1285.    In other words, if it is live at function entry.  */
  1286.  
  1287. int
  1288. regno_uninitialized (regno)
  1289.      int regno;
  1290. {
  1291.   if (n_basic_blocks == 0)
  1292.     return 0;
  1293.  
  1294.   return (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
  1295.       & (1 << (regno % REGSET_ELT_BITS)));
  1296. }
  1297.  
  1298. /* 1 if register REGNO was alive at a place where `setjmp' was called
  1299.    and was set more than once.  Such regs may be clobbered by `longjmp'.  */
  1300.  
  1301. int
  1302. regno_clobbered_at_setjmp (regno)
  1303.      int regno;
  1304. {
  1305.   return (reg_n_sets[regno] > 1
  1306.       && (regs_live_at_setjmp[regno / REGSET_ELT_BITS]
  1307.           & (1 << (regno % REGSET_ELT_BITS))));
  1308. }
  1309.  
  1310. /* Process the registers that are set within X.
  1311.    Their bits are set to 1 in the regset DEAD,
  1312.    because they are dead prior to this insn.
  1313.  
  1314.    If INSN is nonzero, it is the insn being processed
  1315.    and the fact that it is nonzero implies this is the FINAL pass
  1316.    in propagate_block.  In this case, various info about register
  1317.    usage is stored, LOG_LINKS fields of insns are set up.  */
  1318.  
  1319. static void mark_set_1 ();
  1320.  
  1321. static void
  1322. mark_set_regs (needed, dead, x, insn, significant)
  1323.      regset needed;
  1324.      regset dead;
  1325.      rtx x;
  1326.      rtx insn;
  1327.      regset significant;
  1328. {
  1329.   register RTX_CODE code = GET_CODE (x);
  1330.  
  1331.   if (code == SET || code == CLOBBER)
  1332.     mark_set_1 (needed, dead, x, insn, significant);
  1333.   else if (code == PARALLEL)
  1334.     {
  1335.       register int i;
  1336.       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  1337.     {
  1338.       code = GET_CODE (XVECEXP (x, 0, i));
  1339.       if (code == SET || code == CLOBBER)
  1340.         mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
  1341.     }
  1342.     }
  1343. }
  1344.  
  1345. /* Process a single SET rtx, X.  */
  1346.  
  1347. static void
  1348. mark_set_1 (needed, dead, x, insn, significant)
  1349.      regset needed;
  1350.      regset dead;
  1351.      rtx x;
  1352.      rtx insn;
  1353.      regset significant;
  1354. {
  1355.   register int regno;
  1356.   register rtx reg = SET_DEST (x);
  1357.   int subreg_p = 0;
  1358.  
  1359.   if (reg == 0)
  1360.     return;
  1361.  
  1362.   if (GET_CODE (reg) == STRICT_LOW_PART)
  1363.     reg = XEXP (reg, 0);
  1364.  
  1365.   if (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
  1366.       || GET_CODE (reg) == SIGN_EXTRACT)
  1367.     {
  1368.       /* Modifying just one hardware register of a multi-reg value
  1369.      or just a byte field of a register
  1370.      does not mean the value from before this insn is now dead.
  1371.      But it does mean liveness of that register at the end of the block
  1372.      is significant.  */
  1373.       if (REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg))
  1374.     subreg_p = 1;
  1375.  
  1376.       reg = SUBREG_REG (reg);
  1377.     }
  1378.  
  1379.   if (GET_CODE (reg) == REG
  1380.       && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
  1381.       && regno != ARG_POINTER_REGNUM
  1382.       && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
  1383.     /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
  1384.     {
  1385.       register int offset = regno / REGSET_ELT_BITS;
  1386.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1387.       int is_needed = 0;
  1388.  
  1389.       /* Mark it as a significant register for this basic block.  */
  1390.       if (significant)
  1391.     significant[offset] |= bit;
  1392.       /* That's all we do, if we are setting only part of the register.  */
  1393.       if (subreg_p)
  1394.     return;
  1395.  
  1396.       /* If entire register being set, mark it as as dead before this insn.  */
  1397.       dead[offset] |= bit;
  1398.       /* A hard reg in a wide mode may really be multiple registers.
  1399.      If so, mark all of them just like the first.  */
  1400.       if (regno < FIRST_PSEUDO_REGISTER)
  1401.     {
  1402.       int n;
  1403.  
  1404.       /* Nothing below is needed for the stack pointer; get out asap.
  1405.          Eg, log links aren't needed, since combine won't use them.  */
  1406.       if (regno == STACK_POINTER_REGNUM)
  1407.         return;
  1408.  
  1409.       n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1410.       while (--n > 0)
  1411.         {
  1412.           dead[(regno + n) / REGSET_ELT_BITS]
  1413.         |= 1 << ((regno + n) % REGSET_ELT_BITS);
  1414.           if (significant)
  1415.         significant[(regno + n) / REGSET_ELT_BITS]
  1416.           |= 1 << ((regno + n) % REGSET_ELT_BITS);
  1417.           is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
  1418.                 & 1 << ((regno + n) % REGSET_ELT_BITS));
  1419.         }
  1420.     }
  1421.       /* Additional data to record if this is the final pass.  */
  1422.       if (insn)
  1423.     {
  1424.       register rtx y = reg_next_use[regno];
  1425.       register int blocknum = BLOCK_NUM (insn);
  1426.  
  1427.       /* If this is a hard reg, record this function uses the reg.
  1428.          `combine.c' will get confused if LOG_LINKs are made
  1429.          for hard regs.  */
  1430.  
  1431.       if (regno < FIRST_PSEUDO_REGISTER)
  1432.         {
  1433.           register int i;
  1434.           i = HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1435.           if (i == 0)
  1436.         i = 1;
  1437.           do
  1438.         regs_ever_live[regno + --i] = 1;
  1439.           while (i > 0);
  1440.  
  1441.           if (! ((needed[offset] & bit) || is_needed))
  1442.         {
  1443.           /* Note that dead stores have already been deleted if poss.
  1444.              If we get here, we have found a dead store that cannot
  1445.              be eliminated (because the insn does something useful).
  1446.              Indicate this by marking the reg set as dying here.  */
  1447.           REG_NOTES (insn)
  1448.             = gen_rtx (EXPR_LIST, REG_DEAD,
  1449.                    reg, REG_NOTES (insn));
  1450.           reg_n_deaths[REGNO (reg)]++;
  1451.         }
  1452.           return;
  1453.         }
  1454.  
  1455.       /* Keep track of which basic blocks each reg appears in.  */
  1456.  
  1457.       if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
  1458.         reg_basic_block[regno] = blocknum;
  1459.       else if (reg_basic_block[regno] != blocknum)
  1460.         reg_basic_block[regno] = REG_BLOCK_GLOBAL;
  1461.  
  1462.       /* Count (weighted) references, stores, etc.  */
  1463.       reg_n_refs[regno] += loop_depth;
  1464.       reg_n_sets[regno]++;
  1465.       /* The next use is no longer "next", since a store intervenes.  */
  1466.       reg_next_use[regno] = 0;
  1467.       /* The insns where a reg is live are normally counted elsewhere,
  1468.          but we want the count to include the insn where the reg is set,
  1469.          and the normal counting mechanism would not count it.  */
  1470.       reg_live_length[regno]++;
  1471.       if ((needed[offset] & bit) || is_needed)
  1472.         {
  1473.           /* Make a logical link from the next following insn
  1474.          that uses this register, back to this insn.
  1475.          The following insns have already been processed.  */
  1476.           if (y && (BLOCK_NUM (y) == blocknum))
  1477.         LOG_LINKS (y)
  1478.           = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y));
  1479.         }
  1480.       else
  1481.         {
  1482.           /* Note that dead stores have already been deleted when possible
  1483.          If we get here, we have found a dead store that cannot
  1484.          be eliminated (because the same insn does something useful).
  1485.          Indicate this by marking the reg being set as dying here.  */
  1486.           REG_NOTES (insn)
  1487.         = gen_rtx (EXPR_LIST, REG_DEAD,
  1488.                reg, REG_NOTES (insn));
  1489.           reg_n_deaths[REGNO (reg)]++;
  1490.         }
  1491.     }
  1492.     }
  1493. }
  1494.  
  1495. /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
  1496.    This is done assuming the registers needed from X
  1497.    are those that have 1-bits in NEEDED.
  1498.  
  1499.    On the final pass, FINAL is 1.  This means try for autoincrement
  1500.    and count the uses and deaths of each pseudo-reg.
  1501.  
  1502.    INSN is the containing instruction.  */
  1503.  
  1504. static void
  1505. mark_used_regs (needed, live, x, final, insn)
  1506.      regset needed;
  1507.      regset live;
  1508.      rtx x;
  1509.      rtx insn;
  1510.      int final;
  1511. {
  1512.   register RTX_CODE code;
  1513.   register int regno;
  1514.  
  1515.  retry:
  1516.   code = GET_CODE (x);
  1517.   switch (code)
  1518.     {
  1519.     case LABEL_REF:
  1520.     case SYMBOL_REF:
  1521.     case CONST_INT:
  1522.     case CONST:
  1523.     case CONST_DOUBLE:
  1524.     case CC0:
  1525.     case PC:
  1526.     case CLOBBER:
  1527.     case ADDR_VEC:
  1528.     case ADDR_DIFF_VEC:
  1529.     case ASM_INPUT:
  1530.       return;
  1531.  
  1532. #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
  1533.     case MEM:
  1534.       /* Here we detect use of an index register which might
  1535.      be good for postincrement or postdecrement.  */
  1536.       if (final)
  1537.     {
  1538.       rtx addr = XEXP (x, 0);
  1539.       register int size = GET_MODE_SIZE (GET_MODE (x));
  1540.  
  1541.       if (GET_CODE (addr) == REG)
  1542.         {
  1543.           register rtx y;
  1544.           regno = REGNO (addr);
  1545.           /* Is the next use an increment that might make auto-increment? */
  1546.           y = reg_next_use[regno];
  1547.           if (y && GET_CODE (PATTERN (y)) == SET
  1548.           && BLOCK_NUM (y) == BLOCK_NUM (insn)
  1549.           /* Can't add side effects to jumps; if reg is spilled and
  1550.              reloaded, there's no way to store back the altered value.  */
  1551.           && GET_CODE (insn) != JUMP_INSN
  1552.           && (y = SET_SRC (PATTERN (y)),
  1553.               (0
  1554. #ifdef HAVE_POST_INCREMENT
  1555.                || GET_CODE (y) == PLUS
  1556. #endif
  1557. #ifdef HAVE_POST_DECREMENT
  1558.                || GET_CODE (y) == MINUS
  1559. #endif
  1560.                )
  1561.               && XEXP (y, 0) == addr
  1562.               && GET_CODE (XEXP (y, 1)) == CONST_INT
  1563.               && INTVAL (XEXP (y, 1)) == size)
  1564.           && dead_or_set_p (reg_next_use[regno], addr))
  1565.         {
  1566.           rtx use = find_use_as_address (PATTERN (insn), addr, 0);
  1567.  
  1568.           /* Make sure this register appears only once in this insn.  */
  1569.           if (use != 0 && use != (rtx) 1)
  1570.             {
  1571.               /* We have found a suitable auto-increment:
  1572.              do POST_INC around the register here,
  1573.              and patch out the increment instruction that follows. */
  1574.               XEXP (x, 0)
  1575.             = gen_rtx (GET_CODE (y) == PLUS ? POST_INC : POST_DEC,
  1576.                    Pmode, addr);
  1577.               /* Record that this insn has an implicit side effect.  */
  1578.               REG_NOTES (insn)
  1579.             = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn));
  1580.  
  1581.               /* Modify the old increment-insn to simply copy
  1582.              the already-incremented value of our register.  */
  1583.               y = reg_next_use[regno];
  1584.               SET_SRC (PATTERN (y)) = addr;
  1585.  
  1586.               /* If that makes it a no-op (copying the register
  1587.              into itself) then change it to a simpler no-op
  1588.              so it won't appear to be a "use" and a "set"
  1589.              of this register.  */
  1590.               if (SET_DEST (PATTERN (y)) == addr)
  1591.             PATTERN (y) = gen_rtx (USE, VOIDmode, const0_rtx);
  1592.  
  1593.               /* Count an extra reference to the reg for the increment.
  1594.              When a reg is incremented.
  1595.              spilling it is worse, so we want to make that
  1596.              less likely.  */
  1597.               reg_n_refs[regno] += loop_depth;
  1598.               /* Count the increment as a setting of the register,
  1599.              even though it isn't a SET in rtl.  */
  1600.               reg_n_sets[regno]++;
  1601.             }
  1602.         }
  1603.         }
  1604.     }
  1605.       break;
  1606. #endif /* HAVE_POST_INCREMENT or HAVE_POST_DECREMENT */
  1607.  
  1608.     case REG:
  1609.       /* See a register other than being set
  1610.      => mark it as needed.  */
  1611.  
  1612.       regno = REGNO (x);
  1613.       if (regno != FRAME_POINTER_REGNUM)
  1614.       /* && regno != ARG_POINTER_REGNUM) -- and without this.  */
  1615.     /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
  1616.     {
  1617.       register int offset = regno / REGSET_ELT_BITS;
  1618.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1619.       int is_needed = 0;
  1620.  
  1621.       live[offset] |= bit;
  1622.       /* A hard reg in a wide mode may really be multiple registers.
  1623.          If so, mark all of them just like the first.  */
  1624.       if (regno < FIRST_PSEUDO_REGISTER)
  1625.         {
  1626.           int n;
  1627.  
  1628.           /* For stack ptr or arg pointer,
  1629.          nothing below can be necessary, so waste no more time.  */
  1630.           if (regno == STACK_POINTER_REGNUM
  1631.           || regno == ARG_POINTER_REGNUM)
  1632.         return;
  1633.           /* No death notes for global register variables;
  1634.          their values are live after this function exits.  */
  1635.           if (global_regs[regno])
  1636.         return;
  1637.  
  1638.           n = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1639.           while (--n > 0)
  1640.         {
  1641.           live[(regno + n) / REGSET_ELT_BITS]
  1642.             |= 1 << ((regno + n) % REGSET_ELT_BITS);
  1643.           is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
  1644.                 & 1 << ((regno + n) % REGSET_ELT_BITS));
  1645.         }
  1646.         }
  1647.       if (final)
  1648.         {
  1649.           if (regno < FIRST_PSEUDO_REGISTER)
  1650.         {
  1651.           /* If a hard reg is being used,
  1652.              record that this function does use it.  */
  1653.  
  1654.           register int i;
  1655.           i = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1656.           if (i == 0)
  1657.             i = 1;
  1658.           do
  1659.             regs_ever_live[regno + --i] = 1;
  1660.           while (i > 0);
  1661.         }
  1662.           else
  1663.         {
  1664.           /* Keep track of which basic block each reg appears in.  */
  1665.  
  1666.           register int blocknum = BLOCK_NUM (insn);
  1667.  
  1668.           if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
  1669.             reg_basic_block[regno] = blocknum;
  1670.           else if (reg_basic_block[regno] != blocknum)
  1671.             reg_basic_block[regno] = REG_BLOCK_GLOBAL;
  1672.  
  1673.           /* Record where each reg is used, so when the reg
  1674.              is set we know the next insn that uses it.  */
  1675.  
  1676.           reg_next_use[regno] = insn;
  1677.  
  1678.           /* Count (weighted) number of uses of each reg.  */
  1679.  
  1680.           reg_n_refs[regno] += loop_depth;
  1681.         }
  1682.  
  1683.           /* Record and count the insns in which a reg dies.
  1684.          If it is used in this insn and was dead below the insn
  1685.          then it dies in this insn.  */
  1686.  
  1687.           if (!(needed[offset] & bit) && !is_needed
  1688.           && ! find_regno_note (insn, REG_DEAD, regno))
  1689.         {
  1690.           REG_NOTES (insn)
  1691.             = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn));
  1692.           reg_n_deaths[regno]++;
  1693.         }
  1694.         }
  1695.     }
  1696.       return;
  1697.  
  1698.     case SET:
  1699.       {
  1700.     register rtx testreg = SET_DEST (x);
  1701.     int mark_dest = 0;
  1702.  
  1703.     /* Storing in STRICT_LOW_PART is like storing in a reg
  1704.        in that this SET might be dead, so ignore it in TESTREG.
  1705.        but in some other ways it is like using the reg.  */
  1706.     /* Storing in a SUBREG or a bit field is like storing the entire
  1707.        register in that if the register's value is not used
  1708.        then this SET is not needed.  */
  1709.     while (GET_CODE (testreg) == STRICT_LOW_PART
  1710.            || GET_CODE (testreg) == ZERO_EXTRACT
  1711.            || GET_CODE (testreg) == SIGN_EXTRACT
  1712.            || GET_CODE (testreg) == SUBREG)
  1713.       {
  1714.         /* Modifying a single register in an alternate mode
  1715.            does not use any of the old value.  But these other
  1716.            ways of storing in a register do use the old value.  */
  1717.         if (GET_CODE (testreg) == SUBREG
  1718.         && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
  1719.           ;
  1720.         else
  1721.           mark_dest = 1;
  1722.  
  1723.         testreg = XEXP (testreg, 0);
  1724.       }
  1725.  
  1726.     /* If this is a store into a register,
  1727.        recursively scan the only value being stored,
  1728.        and only if the register's value is live after this insn.
  1729.        If the value being computed here would never be used
  1730.        then the values it uses don't need to be computed either.  */
  1731.  
  1732.     if (GET_CODE (testreg) == REG
  1733.         && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
  1734.         && regno != ARG_POINTER_REGNUM
  1735.         && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
  1736. #if 0 /* This was added in 1.25, but screws up death notes for hard regs.
  1737.      It probably isn't really needed anyway.  */
  1738.         && (regno >= FIRST_PSEUDO_REGISTER
  1739.         || INSN_VOLATILE (insn)))
  1740. #endif
  1741.       {
  1742.         register int offset = regno / REGSET_ELT_BITS;
  1743.         register int bit = 1 << (regno % REGSET_ELT_BITS);
  1744.         if ((needed[offset] & bit)
  1745.         /* If insn refers to volatile, we mustn't delete it,
  1746.            so its inputs are all needed.  */
  1747.         || INSN_VOLATILE (insn))
  1748.           {
  1749.         mark_used_regs (needed, live, SET_SRC (x), final, insn);
  1750.         if (mark_dest)
  1751.           mark_used_regs (needed, live, SET_DEST (x), final, insn);
  1752.           }
  1753.         return;
  1754.       }
  1755.       }
  1756.       break;
  1757.     }
  1758.  
  1759.   /* Recursively scan the operands of this expression.  */
  1760.  
  1761.   {
  1762.     register char *fmt = GET_RTX_FORMAT (code);
  1763.     register int i;
  1764.     
  1765.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1766.       {
  1767.     if (fmt[i] == 'e')
  1768.       {
  1769.         /* Tail recursive case: save a function call level.  */
  1770.         if (i == 0)
  1771.           {
  1772.         x = XEXP (x, 0);
  1773.         goto retry;
  1774.           }
  1775.         mark_used_regs (needed, live, XEXP (x, i), final, insn);
  1776.       }
  1777.     else if (fmt[i] == 'E')
  1778.       {
  1779.         register int j;
  1780.         for (j = 0; j < XVECLEN (x, i); j++)
  1781.           mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
  1782.       }
  1783.       }
  1784.   }
  1785. }
  1786.  
  1787. #ifdef AUTO_INC_DEC
  1788.  
  1789. static int
  1790. try_pre_increment_1 (insn)
  1791.      rtx insn;
  1792. {
  1793.   /* Find the next use of this reg.  If in same basic block,
  1794.      make it do pre-increment or pre-decrement if appropriate.  */
  1795.   rtx x = PATTERN (insn);
  1796.   int amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
  1797.         * INTVAL (XEXP (SET_SRC (x), 1)));
  1798.   int regno = REGNO (SET_DEST (x));
  1799.   rtx y = reg_next_use[regno];
  1800.   if (y != 0
  1801.       && BLOCK_NUM (y) == BLOCK_NUM (insn)
  1802.       && try_pre_increment (y, SET_DEST (PATTERN (insn)),
  1803.                 amount))
  1804.     {
  1805.       /* We have found a suitable auto-increment
  1806.      and already changed insn Y to do it.
  1807.      So flush this increment-instruction.  */
  1808.       PUT_CODE (insn, NOTE);
  1809.       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1810.       NOTE_SOURCE_FILE (insn) = 0;
  1811.       /* Count a reference to this reg for the increment
  1812.      insn we are deleting.  When a reg is incremented.
  1813.      spilling it is worse, so we want to make that
  1814.      less likely.  */
  1815.       reg_n_refs[regno] += loop_depth;
  1816.       reg_n_sets[regno]++;
  1817.       return 1;
  1818.     }
  1819.   return 0;
  1820. }
  1821.  
  1822. /* Try to change INSN so that it does pre-increment or pre-decrement
  1823.    addressing on register REG in order to add AMOUNT to REG.
  1824.    AMOUNT is negative for pre-decrement.
  1825.    Returns 1 if the change could be made.
  1826.    This checks all about the validity of the result of modifying INSN.  */
  1827.  
  1828. static int
  1829. try_pre_increment (insn, reg, amount)
  1830.      rtx insn, reg;
  1831.      int amount;
  1832. {
  1833.   register rtx use;
  1834.  
  1835.   /* Nonzero if we can try to make a pre-increment or pre-decrement.
  1836.      For example, addl $4,r1; movl (r1),... can become movl +(r1),...  */
  1837.   int pre_ok = 0;
  1838.   /* Nonzero if we can try to make a post-increment or post-decrement.
  1839.      For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
  1840.      It is possible for both PRE_OK and POST_OK to be nonzero if the machine
  1841.      supports both pre-inc and post-inc, or both pre-dec and post-dec.  */
  1842.   int post_ok = 0;
  1843.  
  1844.   /* Nonzero if the opportunity actually requires post-inc or post-dec.  */
  1845.   int do_post = 0;
  1846.  
  1847.   /* From the sign of increment, see which possibilities are conceivable
  1848.      on this target machine.  */
  1849. #ifdef HAVE_PRE_INCREMENT
  1850.   if (amount > 0)
  1851.     pre_ok = 1;
  1852. #endif
  1853. #ifdef HAVE_POST_INCREMENT
  1854.   if (amount > 0)
  1855.     post_ok = 1;
  1856. #endif
  1857.  
  1858. #ifdef HAVE_PRE_DECREMENT
  1859.   if (amount < 0)
  1860.     pre_ok = 1;
  1861. #endif
  1862. #ifdef HAVE_POST_DECREMENT
  1863.   if (amount < 0)
  1864.     post_ok = 1;
  1865. #endif
  1866.  
  1867.   if (! (pre_ok || post_ok))
  1868.     return 0;
  1869.  
  1870.   /* It is not safe to add a side effect to a jump insn
  1871.      because if the incremented register is spilled and must be reloaded
  1872.      there would be no way to store the incremented value back in memory.  */
  1873.  
  1874.   if (GET_CODE (insn) == JUMP_INSN)
  1875.     return 0;
  1876.  
  1877.   use = 0;
  1878.   if (pre_ok)
  1879.     use = find_use_as_address (PATTERN (insn), reg, 0);
  1880.   if (post_ok && (use == 0 || use == (rtx) 1))
  1881.     {
  1882.       use = find_use_as_address (PATTERN (insn), reg, -amount);
  1883.       do_post = 1;
  1884.     }
  1885.  
  1886.   if (use == 0 || use == (rtx) 1)
  1887.     return 0;
  1888.  
  1889.   if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
  1890.     return 0;
  1891.  
  1892.   XEXP (use, 0) = gen_rtx (amount > 0
  1893.                ? (do_post ? POST_INC : PRE_INC)
  1894.                : (do_post ? POST_DEC : PRE_DEC),
  1895.                Pmode, reg);
  1896.  
  1897.   /* Record that this insn now has an implicit side effect on X.  */
  1898.   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn));
  1899.   return 1;
  1900. }
  1901.  
  1902. #endif /* AUTO_INC_DEC */
  1903.  
  1904. /* Find the place in the rtx X where REG is used as a memory address.
  1905.    Return the MEM rtx that so uses it.
  1906.    If PLUSCONST is nonzero, search instead for a memory address equivalent to
  1907.    (plus REG (const_int PLUSCONST)).
  1908.  
  1909.    If such an address does not appear, return 0.
  1910.    If REG appears more than once, or is used other than in such an address,
  1911.    return (rtx)1.  */
  1912.  
  1913. static rtx
  1914. find_use_as_address (x, reg, plusconst)
  1915.      register rtx x;
  1916.      rtx reg;
  1917.      int plusconst;
  1918. {
  1919.   enum rtx_code code = GET_CODE (x);
  1920.   char *fmt = GET_RTX_FORMAT (code);
  1921.   register int i;
  1922.   register rtx value = 0;
  1923.   register rtx tem;
  1924.  
  1925.   if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
  1926.     return x;
  1927.  
  1928.   if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
  1929.       && XEXP (XEXP (x, 0), 0) == reg
  1930.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1931.       && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
  1932.     return x;
  1933.  
  1934.   if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
  1935.     {
  1936.       /* If REG occurs inside a MEM used in a bit-field reference,
  1937.      that is unacceptable.  */
  1938.       if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
  1939.     return (rtx) 1;
  1940.     }
  1941.  
  1942.   if (x == reg)
  1943.     return (rtx) 1;
  1944.  
  1945.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1946.     {
  1947.       if (fmt[i] == 'e')
  1948.     {
  1949.       tem = find_use_as_address (XEXP (x, i), reg, plusconst);
  1950.       if (value == 0)
  1951.         value = tem;
  1952.       else if (tem != 0)
  1953.         return (rtx) 1;
  1954.     }
  1955.       if (fmt[i] == 'E')
  1956.     {
  1957.       register int j;
  1958.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1959.         {
  1960.           tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
  1961.           if (value == 0)
  1962.         value = tem;
  1963.           else if (tem != 0)
  1964.         return (rtx) 1;
  1965.         }
  1966.     }
  1967.     }
  1968.  
  1969.   return value;
  1970. }
  1971.  
  1972. /* Write information about registers and basic blocks into FILE.
  1973.    This is part of making a debugging dump.  */
  1974.  
  1975. void
  1976. dump_flow_info (file)
  1977.      FILE *file;
  1978. {
  1979.   register int i;
  1980.   static char *reg_class_names[] = REG_CLASS_NAMES;
  1981.  
  1982.   fprintf (file, "%d registers.\n", max_regno);
  1983.  
  1984.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1985.     if (reg_n_refs[i])
  1986.       {
  1987.     enum reg_class class;
  1988.     fprintf (file, "\nRegister %d used %d times across %d insns",
  1989.          i, reg_n_refs[i], reg_live_length[i]);
  1990.     if (reg_basic_block[i] >= 0)
  1991.       fprintf (file, " in block %d", reg_basic_block[i]);
  1992.     if (reg_n_deaths[i] != 1)
  1993.       fprintf (file, "; dies in %d places", reg_n_deaths[i]);
  1994.     if (reg_n_calls_crossed[i] == 1)
  1995.       fprintf (file, "; crosses 1 call", reg_n_calls_crossed[i]);
  1996.     else if (reg_n_calls_crossed[i])
  1997.       fprintf (file, "; crosses %d calls", reg_n_calls_crossed[i]);
  1998.     if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
  1999.       fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
  2000.     class = reg_preferred_class (i);
  2001.     if (class != GENERAL_REGS)
  2002.       {
  2003.         if (reg_preferred_or_nothing (i))
  2004.           fprintf (file, "; %s or none", reg_class_names[(int) class]);
  2005.         else
  2006.           fprintf (file, "; pref %s", reg_class_names[(int) class]);
  2007.       }
  2008.     if (REGNO_POINTER_FLAG (i))
  2009.       fprintf (file, "; pointer");
  2010.     fprintf (file, ".\n");
  2011.       }
  2012.   fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
  2013.   for (i = 0; i < n_basic_blocks; i++)
  2014.     {
  2015.       register rtx head, jump;
  2016.       register int regno;
  2017.       fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
  2018.            i,
  2019.            INSN_UID (basic_block_head[i]),
  2020.            INSN_UID (basic_block_end[i]));
  2021.       /* The control flow graph's storage is freed
  2022.      now when flow_analysis returns.
  2023.      Don't try to print it if it is gone.  */
  2024.       if (basic_block_drops_in)
  2025.     {
  2026.       fprintf (file, "Reached from blocks: ");
  2027.       head = basic_block_head[i];
  2028.       if (GET_CODE (head) == CODE_LABEL)
  2029.         for (jump = LABEL_REFS (head);
  2030.          jump != head;
  2031.          jump = LABEL_NEXTREF (jump))
  2032.           {
  2033.         register int from_block = BLOCK_NUM (CONTAINING_INSN (jump));
  2034.         fprintf (file, " %d", from_block);
  2035.           }
  2036.       if (basic_block_drops_in[i])
  2037.         fprintf (file, " previous");
  2038.     }
  2039.       fprintf (file, "\nRegisters live at start:");
  2040.       for (regno = 0; regno < max_regno; regno++)
  2041.     {
  2042.       register int offset = regno / REGSET_ELT_BITS;
  2043.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  2044.       if (basic_block_live_at_start[i][offset] & bit)
  2045.           fprintf (file, " %d", regno);
  2046.     }
  2047.       fprintf (file, "\n");
  2048.     }
  2049.   fprintf (file, "\n");
  2050. }
  2051.